const app = getApp()
import { makePhoneCall } from '../utils/http.js'
import { throttle } from "../utils/throttle.js"
module.exports = {
  /**
  * 表单提交事件，收集formId　
  * author dzl
  */
  formSubmit: function (e) {
    let formId = e.detail.formId
    //处理保存推送码
    app.dealFormIds(formId);
    app.saveFormIds()
  },
  
  /**
   * 登录页面表单提交
   */
  formSubmitLogin: throttle(function(e) {
    let formId = e.detail.formId
    //处理保存推送码
    app.dealFormIds(formId)
    app.saveFormIds()
    // 手机号数据更新
    this.setData({
      phonenumber: e.detail.value.phonenumber,
      btnCode: e.detail.value.btnCode
    })
    // 进行登录
    this.login()
  }, 2000),
  /**
   * 所有列表拨打电话，所有列表详情拨打电话
   * callId                 电话id
   * phonenumber  电话号码
   */
  phoneCall (res, code, swindex) {
    if (res.statusCode === 200) {
      // 拿到电话
      let callId = res.result.callId
      app.phonenumber = res.result.switchNumber
      // 拨打电话进行跳转
      makePhoneCall().then(res => {
        var model = {}
        model.callId = callId
        model.swindex = swindex
        // 房客编号
        if (code[0] !== null) {
          model.resourceCode = code[0]
          // 房客类型
          model.page = 'phone_list'
          model.utype = this.data.telData.utype
          model.resourceType = this.data.telData.resourceType
          // 跳转进入跟进描述
          wx.redirectTo({
            url: `../follow_describe/index?model=${JSON.stringify(model)}`
          })
       }
        // 跳转到电话列表页
      })
    }
    res.message !== "成功" ? wx.showToast({
      title: res.message,
      icon: 'none'
    }):""
  }
}